package com.gears_software.bbnetwork.views;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gears_software.bbnetwork.R;
import com.gears_software.bbnetwork.datas.models.AchieveBankIconUrls;
import com.gears_software.bbnetwork.utlis.Image;
import com.gears_software.bbnetwork.utlis.ImageFileCache;
import com.gears_software.common.net.avatarupload.UploadFileUtil;

@EViewGroup(R.layout.window_item)
public class YinghangItemView extends RelativeLayout {

	@ViewById
	ImageView iamge_icon;//图标
	
	@ViewById
	TextView txt_name;//名称
	
	public YinghangItemView(Context context) {
		super(context);
	}
	
	public void bind(AchieveBankIconUrls model){
		iamge_icon.setImageBitmap(null);
		if(model!=null){
			Bitmap bit = ImageFileCache.getFileImage(model.getBankIconUrl());
			if(bit!=null){
				iamge_icon.setImageBitmap(bit);
			}else{
				getBitmap(model.getBankIconUrl());
			}
//			if(model.getBankIconUrl()!=null){
//				getImage(model.getBankIconUrl());
//			}
			txt_name.setText(model.getBankName());
		}
	}
	
	@Background
	void getBitmap(String url){
		Bitmap bitmap = UploadFileUtil.httpsGetBitmap(url);
		ImageFileCache.saveFile(bitmap, url);
		setBitmap(bitmap);
	}
	
	@UiThread
	void setBitmap(Bitmap bitmap){
		iamge_icon.setImageBitmap(bitmap);
	}
	
//	@Background
//	void getImage(String str){
//		Bitmap bitmap = UploadFileUtil.httpsGetBitmap(str);
//		setImage(bitmap);
//	}
//	
//	@UiThread
//	void setImage(Bitmap bitmap){
//		iamge_icon.setImageBitmap(bitmap);
//	}

}
